package com.leetcode.code;

import java.util.ArrayList;
import java.util.List;

/**
 * 已发
 */
public class LeetCode0557Java {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.reverseWords("Let's take LeetCode contest"));
    }

    private static class Solution {
        public String reverseWords(String s) {
            String[] splitWords = s.split(" ");
            List<String> reverseWords = new ArrayList<String>();
            for (String words : splitWords) {
                char[] wordsChars = words.toCharArray();
                StringBuilder result = new StringBuilder();
                for (int i = wordsChars.length - 1; i >= 0; i--) {
                    result.append(wordsChars[i]);
                }
                reverseWords.add(result.toString());
            }

            //        ArrayList charList = new ArrayList(Arrays.asList(chars));
            //        Collections.reverse(charList);
            StringBuilder reverseResult = new StringBuilder();
            for (String reverseWord : reverseWords) {
                reverseResult.append(reverseWord + " ");
            }
            return reverseResult.toString().substring(0, reverseResult.length() - 1);
        }
    }
}
